import sys
from datetime import date
import doctest
import os
import time
def reverseWords(input):
    # 通过空格将字符串分隔符，把各个单词分隔为列表
    inputWords = input.split(" ")

    # 翻转字符串
    # 假设列表 list = [1,2,3,4],
    # list[0]=1, list[1]=2 ，而 -1 表示最后一个元素 list[-1]=4 ( 与 list[3]=4 一样)
    # inputWords[-1::-1] 有三个参数
    # 第一个参数 -1 表示最后一个元素
    # 第二个参数为空，表示移动到列表末尾
    # 第三个参数为步长，-1 表示逆向
    inputWords = inputWords[-1::-1]

    # 重新组合字符串
    output = ' '.join(inputWords)

    return output
def __b(a='hello'):
   print('''注解b''',a)
def a():
     print('''注解a''')
     __b()


def foo():
        print("starting...")
        while True:
            res = yield 4
            print("res:", res)

class MyNumbers:
    def __iter__(self):
        self.a = 1
        return self

    def __next__(self):
        if self.a <= 20:
            x = self.a
            self.a += 1
            return x
        else:
            raise StopIteration

def multiply(a, b):
        """
        >>> multiply(4, 3)
        12
        >>> multiply('a', 3)
        'aaa'
        """
        return a * b
def test(value1, value2=None):
        print("%s threading is printed %s, %s" % (threading.current_thread().name, value1, value2))
        # time.sleep(4)
        return 'finished'

def test_result(future):
        print(future.result())
if __name__ == "__main__":
    # myclass = MyNumbers()
    # myiter = iter(myclass)
    # while True:
    #         try:
    #             print(next(myiter))
    #
    #         except StopIteration:
    #             print("StopIteration")
    #

    
 
    # g = foo()
    # print(next(g))
    # print("*" * 20)
    # print(next(g))
    # str =  list("runoob")
    #
    # try:
    #     raise ZeroDivisionError
    # except (AssertionError,ZeroDivisionError) as error:
    #     print(error)
    # else:
    #     try:
    #         with open('file.log') as file:
    #             read_data = file.read()
    #     except FileNotFoundError as fnf_error:
    #         print(fnf_error)
    # finally:
    #     print('这句话，无论异常是否发生都会执行。')
    #
    #
    # class MyError(Exception):
    #     def __init__(self, value):
    #         self.value = value
    #
    #     def __str__(self):
    #         return repr(self.value)
    #
    #
    # try:
    #     raise MyError(2 * 2)
    # except MyError as e:
    #     print('My exception occurred, value:', e.value)
    #
    #     try:
    #
    #         raise KeyboardInterrupt
    #     except KeyboardInterrupt as e:
    #         print(e.__class__)
    #     finally:
    #
    #         print('Goodbye, world!')
    # assert 1==1
    # assert ('linux' in sys.platform)
    #
    #
    # class MyClass:
    #     """一个简单的类实例"""
    #     i = 12345
    #
    #     def f(self):
    #         return 'hello world'
    #
    #
    # # 实例化类
    # x = MyClass()
    # y = MyClass()
    # y.i = 123
    # # 访问类的属性和方法
    # print("MyClass 类的属性 i 为：", x.i)
    # print("MyClass 类的方法 f 输出为：", x.f())
    #
    # print("MyClass 类的属性 i 为：", y.i)
    # print("MyClass 类的方法 f 输出为：", y.f())
    #

    # a=1
    # class people:
    #     # 定义基本属性
    #     name = ''
    #     age = 0
    #     # 定义私有属性,私有属性在类外部无法直接进行访问
    #     __weight = 0
    #     global num
    #     # 定义构造方法
    #     def __init__(self, n, a, w):
    #         self.name = n
    #         self.age = a
    #         self.__weight = w
    #         print(self.__class__.__name__)
    #
    #     def speak(self):
    #         num = 'xiugai'
    #         print("%s 说: 我 %d 岁。" % (self.name, self.age))
    #         print(num)
    #


    # 实例化类
    # p = people('runoob', 10, 30)
    # p.speak()
    #
    # num = 1
    # def fun1():
    #     global num  # 需要使用 global 关键字声明
    #     print(num)
    #     num = 123
    #     print(num)
    #
    #
    # fun1()
    # print(num)

    # def outer():
    #     num = 10
    #
    #     def inner():
    #         # nonlocal num  # nonlocal关键字声明
    #         num = 100
    #         print(num)
    #
    #     inner()
    #     print(num)
    #
    #
    # outer()
    # print (dir(os))
    # print(date.today())
    # doctest.testmod()
    # import doctest
    #
    # doctest.testmod(verbose=True)
    # print(isinstance('12',str)) ,str(),repr()
    # def  a():
    #     print('hello')
    #     return 'a'
    # def b(f):
    #     print(f())
    # b(a)
    #
    #
    # def outer(x):
    #     def inner():
    #         return '戴了inner牌帽子的 ' + x()
    #
    #     return inner
    #
    #
    # @outer
    # def func():
    #     return '函数func'
    #
    #
    # print(func().__doc__)
    # class A(object):
    #     def __method(self):
    #         print
    #         "I'm a method in A"
    #
    #     def method(self):
    #         self.__method()
    #         a = A()
    #         a.method()
    import threading
    # from concurrent.futures import ThreadPoolExecutor
    # treadpool=ThreadPoolExecutor(max_workers=3,thread_name_prefix='test_')
    # future=''
    # for i in range(0,10):
    #     future = treadpool.submit(test, i,i+1)
    #     future.add_done_callback(test_result)
    #     # print(future.result())
    # # 关闭线程池
    # print('\n'+'hello')
    # treadpool.shutdown(wait=True)
    #
    def test(value1, value2=None):
        print("%s threading is printed %s, %s" % (threading.current_thread().name, value1, value2))


    #     time.sleep(2)

    if __name__ == "__main__":
        from concurrent.futures import ThreadPoolExecutor
        threadPool = ThreadPoolExecutor(max_workers=4, thread_name_prefix="test_")
        for i in range(0, 10):
            #         test(str(i), str(i+1))
            threadPool.map(test, [i],
                           [i + 1])  # 这是运行一次test的参数，众所周知map可以让test执行多次，即一个[]代表一个参数，一个参数赋予不同的值即增加[]的长度如从[1]到[1,2,3]
        threadPool.shutdown(wait=True)
